package com.wlr.study.pointsword;

import java.util.LinkedList;
/**
 * 双栈实现队列
 * @author lrwang
 * @version 1.0
 * @date 2022/4/2 19:18
 */
public class Offer09 {
    private LinkedList<Integer> stack1;
    private LinkedList<Integer> stack2;

    public Offer09() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            return -1;
        }
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }
}
